package servlet;

import bean.AdminBean;
import bean.CustomerBean;
import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class AdminModifyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int aid =Integer.parseInt(request.getParameter("aid"));
        String sql ="SELECT * FROM admin WHERE aid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            System.out.println(ps.toString());
            ps.setInt(1,aid);
            ResultSet set = ps.executeQuery();
            set.absolute(1);
                AdminBean ad = new AdminBean();
                ad.setAid(set.getInt(1));
                ad.setName(set.getString(2));
                ad.setSex(set.getString(3));
                ad.setAge(set.getInt(4));
                ad.setTel(set.getString(5));
                ad.setAddress(set.getString(6));
                ad.setWid(set.getInt(7));
            HttpSession session = request.getSession();
            session.setAttribute("ad",ad);
            request.getRequestDispatcher("adminmodify.jsp").forward(request,response);
        }catch (Exception e) {
            e.printStackTrace();
        }


    }
}

